package com.xieyingwangluo.yxpart.mapper;

import com.xieyingwangluo.yxpart.entity.UserModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface UserMapper {

    /**
     * 新增保存
     *
     * @return
     */
    //@CacheEvict(value="d_user",allEntries = true)
    int add(UserModel user);

    /**
     * 编辑用户信息
     *
     * @param user
     */
    //@CacheEvict(value="d_user",allEntries = true)
    int update(UserModel user);

    /**
     * 修改密码
     */
    //@CacheEvict(value="d_user",allEntries = true)
    @Update("update user set pwd=#{pwd} where noid=#{noid}")
    int updPwd(@Param("noid") String noid, @Param("pwd") String pwd);


    /**
     * 根据id获取用户信息
     *
     * @param noid
     * @return
     */
    //@Cacheable(value="d_demo",key="'UserMapper_getById_'+#noid")
    UserModel getById(@Param("noid") String noid);

    /**
     * 根据用户名获取用户信息
     *
     * @param name
     * @return
     */
    //@Cacheable(value="d_user",key="'UserMapper_getByUsercode_'+#p0")
    @Select("select * from user where name=#{name}")
    UserModel getByUsercode(@Param("name") String name);


    //登录
    @Select("select noid,tel,name,head_img,intg,state,vip,create_time from user where tel=#{tel} and pwd=#{pwd}")
    UserModel checklogin(@Param("tel") String tel, @Param("pwd") String pwd);

    //根据电话号码查询用户
    @Select("select * from user where tel=#{tel}")
    List<UserModel> selT(@Param("tel") String tel);

    /**
     * 获取用户列表
     *
     * @return
     */
    List<UserModel> selA(UserModel userModel);

    //更新用户状态
    @Update("update user set state=#{state} where noid=#{noid}")
    int updS(@Param("noid") String noid, @Param("state") Integer state);

    //根据用户状态查询用户
    @Select("select * from user where state=#{state}")
    List<UserModel> selS(@Param("state") int state);

    //根据状态和用户昵称进行模糊查询
    List<UserModel> selName(UserModel userModel);

}
